﻿using System;
using fastCSharp;

namespace diantou.web.onlineJudge
{
    /// <summary>
    /// 测试数据相关调用
    /// </summary>
    [fastCSharp.code.cSharp.webCall]
    class problemTestData : fastCSharp.code.cSharp.webCall.call<problemTestData>
    {
        /// <summary>
        /// 下载测试数据
        /// </summary>
        /// <param name="problemId"></param>
        /// <param name="testId"></param>
        /// <param name="isInput"></param>
        [fastCSharp.code.cSharp.webCall]
        public void Download(int problemId, int testId, bool isInput)
        {
            diantou.dataAccess.user user = pub.GetSessionUser(this);
            if (user != null)
            {
                diantou.dataAccess.tcpCall.problemTestData.download(problemId, testId, user.Id, isInput, data =>
                {
                    if (data.Type == fastCSharp.net.returnValue.type.Success)
                    {
                        createResponse();
                        try
                        {
                            Response.SetTextContentType();
                            if (data.Value == null) response("没有可用的 点头盾");
                            else
                            {
                                Response.ContentDisposition = ("attachment; filename=51nod_Problem_" + problemId.toString() + "_Test_" + testId.toString() + (isInput ? "_In" : "_Out") + ".txt").getBytes();
                                base.response(data.Value);
                            }
                        }
                        finally { responseEnd(); }
                    }
                    else serverError500();
                });
            }
            else NotFound404();
        }
    }
}
